package com.sunspring.zdcall.websockt;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.messaging.SessionConnectEvent;

import javax.websocket.Session;

/**
 * 监听wb连接
 * @Author WuLei
 * @Date 2018/11/26  15:52
 */
@Component
public class StompConnectEventListener implements ApplicationListener<SessionConnectEvent> {

    @Autowired
    private SessionManager sessionManager;

    @Override
    public void onApplicationEvent(SessionConnectEvent sessionConnectEvent) {
//        StompHeaderAccessor sha = StompHeaderAccessor.wrap(sessionConnectEvent.getMessage());
//        String classId = sha.getFirstNativeHeader("classId");
//        String sessionId = sha.getSessionId();
//        switch (sha.getCommand()) {
//            case CONNECT:
//                System.out.println("科室：" + classId + "启动");
//                sessionManager.registerSession(classId, sessionId);
//                break;
//            default:
//                break;
//        }
        System.out.println("已有用户连接");
    }
}
